<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-08-06 21:14:27
 * @LastEditTime: 2020-03-11 17:17:23
 * @LastEditors: Please set LastEditors
 -->
<!doctype html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport"
		content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0,viewport-fit=cover" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title>Hello APP</title>
	<link rel="stylesheet" type="text/css" href="../css/vant.css">
	<link rel="stylesheet" type="text/css" href="../css/base.css" />
	<script type="text/javascript" src="../script/jquery.js"></script>
	<script type="text/javascript" src="../script/layer/mobile/layer.js"></script>
	<script type="text/javascript" src="../script/vue.min.js"></script>
	<script type="text/javascript" src="../script/vant.min.js"></script>
	<script type="text/javascript" src="../script/fastclick.js"></script>
	<script type="text/javascript" src="../script/base.js"></script>
	<script type="text/javascript" src="../script/db.js"></script>
	<style type="text/css">
		/* .head {
			height: 70px!important;
			line-height: 70px!important;
		}

		.body-no-bottom {
			height: calc(100% - 70px);
			position: relative;
		} */
		.content {
			background: #fff !important;
		}

		.van-search {
			padding-bottom: 0;
			background: #cd1b21 !important;
		}

		.bg {
			background: #cd1b21;
			height: 68px;
		}

		.main {
			padding: 0 15px;
			margin-top: -60px;
		}

		.main>div {
			background: #fff;
			border-radius: 2px;
			padding: 15px;
			box-shadow: 0 0 5px rgb(200, 198, 198);
		}

		.main-1 {
			color: #3a3a3a;
			font-size: 15px;
		}

		.main-2 {
			line-height: 40px;
			color: #f95000;
			font-weight: 700;
			font-size: 22px;
			text-align: center;
		}

		.main-3 {
			font-size: 13px;
			text-align: center;
			padding: 10px 0;
			background: #f2f2f5;
			border-radius: 4px;
			color: #b0b0b0;
		}

		.main-3 .value {
			font-weight: 700;
			color: #f95000;
			font-size: 13px;
		}

		.img {
			width: 50px;
			height: 50px;
			text-align: center;
			border-radius: 25px;
			padding: 11px;
			position: relative;
		}

		.img img {
			height: 28px;
			vertical-align: middle;
		}

		.img-text {
			font-size: 14px;
			margin-top: 6px;
		}

		.notice {
			margin-top: 10px;
			background: #ffffff;
			padding: 10px;
			color: #3a3a3a;
		}

		.notice>div {
			position: relative;
		}

		.notice .notice-img {
			position: absolute;
			left: 0;
			top: 50%;
			width: 30px;
			padding-left: 10px;
			-webkit-transform: translateY(-50%);
			transform: translateY(-50%);
		}

		.notice .notice-img img {
			width: 20px;
		}

		.notice .notice-detail {
			padding: 0 30px 0 40px;
			line-height: 24px;
			font-size: 13px;
		}

		.notice .notice-detail .notice-info {
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
		}

		.notice .notice-detail .store {
			color: #000;
		}

		.notice .notice-detail .result {
			color: #969799;
			margin-right: 4px;
		}

		.notice .notice-arrow {
			position: absolute;
			top: 50%;
			right: 0;
			-webkit-transform: translateY(-50%);
			transform: translateY(-50%);
		}

		/* .button .van-col {
			margin-bottom: 10px;
		} */

		.commonly-used {
			text-align: center;
			margin-top: 10px;
			background: #ffffff;
			color: #3a3a3a;
		}

		.label {
			height: 30px;
			line-height: 30px;
			padding: 0 10px 10px 10px;
			text-align: left;
			font-size: 15px;
		}

		.label * {
			vertical-align: middle;
		}

		.label img {
			width: 20px;
			margin-right: 5px;
		}

		.rotate {
			-webkit-animation: rotate .8s linear infinite;
			animation: rotate .6s linear infinite;
		}

		@-webkit-keyframes rotate {

			0% {
				-webkit-transform: rotate(0deg);
			}

			25% {
				-webkit-transform: rotate(100deg);
			}

			50% {
				-webkit-transform: rotate(200deg);
			}

			75% {
				-webkit-transform: rotate(300deg);
			}

			100% {
				-webkit-transform: rotate(360deg);
			}

		}

		@keyframes rotate {

			0% {
				-webkit-transform: rotate(0deg);
			}

			25% {
				-webkit-transform: rotate(100deg);
			}

			50% {
				-webkit-transform: rotate(200deg);
			}

			75% {
				-webkit-transform: rotate(300deg);
			}

			100% {
				-webkit-transform: rotate(360deg);
			}

		}

		.undeal {
			position: absolute;
			right: -4px;
			top: -4px;
			color: #fff;
			background: #cd1b21;
			width: 20px;
			height: 20px;
			line-height: 20px;
			text-align: center;
			border-radius: 100px;
			font-size: 13px;
		}
	</style>
</head>

<body>
	<div id="app" v-cloak>
		<div class="init-full">
			<div class="head">
				<form action="" style="margin-top: -5px;">
					<van-search placeholder="查询产品库存" v-model="indexSearchKey" shape="round" show-action
						@search="searchInventory">
						<van-icon name="scan" slot="action" color="#fff" size="34" style="vertical-align: middle;"
							@click="openScan">
						</van-icon>
					</van-search>
				</form>
			</div>
			<div class="body-no-bottom">
				<div class="content">
					<div class="bg"></div>
					<div class="main">
						<div @click="openWinPage('dataAggregation')">
							<div class="main-1">
								<van-row>
									<!-- <van-col span="10">
										<div style="text-align: center;">本月活跃客户</div>
										<div class="main-2">{{statistics.NClint || 0}}</div>
									</van-col> -->
									<van-col span="4">

									</van-col>
									<van-col span="16">

										<div style="text-align: center;font-weight: 800">本月销售额</div>
										<div class="main-2">￥{{statistics.XSMoney || 0}}</div>
									</van-col>
									<van-col span="4">
										<span style="float: right;margin-top: -5px;" @click.stop="setDataRefresh">
											<van-icon name="replay" color="#cd1b21" size="24"
												:class="isRotate?'rotate':''">
											</van-icon>
										</span>
									</van-col>
								</van-row>

							</div>
							<div class="main-3">
								<van-row>
									<van-col span="8">
										<div class="value" style="line-height: 18px;">{{statistics.NClint || 0}}</div>
										<div>本月活跃客户</div>
									</van-col>
									<van-col span="8">
										<div class="value">￥{{statistics.PJMoney || 0}}</div>
										<div>客户平均销售额</div>
									</van-col>
									<van-col span="8">
										<div class="value">￥{{statistics.SKMoney || 0}}</div>
										<div>本月回款</div>
									</van-col>
									<!-- <van-col span="8">
										<div class="value">￥{{statistics.XMMoney || 0}}</div>
										<div>销售毛利</div>
									</van-col> -->
								</van-row>
							</div>
						</div>
					</div>
					<div class="commonly-used">
						<div class="label">
							<img src="../image/used.png" />
							<span>我的常用功能</span>
						</div>
						<van-grid :column-num="4" :border="false">
							<van-grid-item v-for="row in usedList" @click="openPage(row)">
								<div class="img" :style="{background:row.AP_Colour}">
									<img :src="row.PIC_PH || '../image/module/module_default.png'" />
									<div class="undeal" v-show="row.unDealNum">{{row.unDealNum}}
									</div>
								</div>
								<div class="img-text">{{row.APFunName}}</div>
							</van-grid-item>

							<van-grid-item @click="openWinPage('moduleConfig')">
								<div class="img" style="background:#b5b5b5">
									<img src="../image/module/module-config.png" />
								</div>
								<div class="img-text">功能配置</div>
							</van-grid-item>
						</van-grid>
					</div>
				</div>
				<van-loading v-if="showLoading" />
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	var vm;
	apiready = function () {
		//$('.init-full').show();

		DB.initDatabase(function () {
			DB.createTable(function () {

			});
		})

		api.addEventListener({
			name: 'smartupdatefinish'
		}, function (ret, err) {
			var systemType = api.systemType;
			if (systemType == "ios") {
				var value = ret.value;
				var extra = value[0];
				api.alert({
					title: '系统已经更新完成',
					msg: '点击确定关闭程序，重新打开后更新生效。',
					buttons: ['确定']
				}, function (ret, err) {
					if (ret.buttonIndex == "1") {
						api.closeWidget({
							id: 'A6019933686735', //这里改成自己的应用ID
							retData: {
								name: 'closeWidget'
							},
							silent: true
						});
					} else {
					}
				});
			}
		});

		api.addEventListener({
			name: 'setCommonFunctions'
		}, function (ret, err) {
			var moduleArray = ret.value.moduleArray;
			window.localStorage.setItem('usedList', JSON.stringify(moduleArray));

			vm.getModuleList();
		})

		api.addEventListener({
			name: 'setDealNum'
		}, function (ret, err) {
			vm.getDealNum();
		})

		var FNScanner = api.require('FNScanner');
		var userInfo = FLD.getUserInfo();

		vm = new Vue({
			el: '#app',
			data: {
				showLoading: false,
				isRotate: false,
				indexSearchKey: '',
				unDealNum: 0,
				statistics: [],
				noticeList: [],
				moduleList: [],
				usedList: []
			},
			created: function () {
				var that = this;

				that.getModuleList();

				that.getUserfulData(1);

				setInterval(function () {
					that.getUserfulData(0);
					that.getUndealNum();
				}, 5000)

				that.getUndealNum();
			},
			methods: {
				getDealNum() {
					var that = this;
					var obj = {
						BranchID: userInfo.S_BranchID,
						Status: 0
					}
					FLD.ajax('getBsOrderList', obj, function (res) {
						that.unDealNum = res.ds.length;
					})
				},
				getModuleList() {
					var that = this;
					FLD.ajax('AP_GetUserNM', {}, function (res) {
						that.moduleList = res.ds1;
						var usedList = [];
						var moduleArray = JSON.parse(window.localStorage.getItem('usedList'));
						if (moduleArray === null) {
							var localUsedList = [];
							for (var i in that.moduleList) {
								if (that.moduleList[i].IsMR == 1) {
									localUsedList.push(that.moduleList[i].APPFunID)
									usedList.push(that.moduleList[i])
								}
							}
							window.localStorage.setItem('usedList', JSON.stringify(localUsedList));
						}
						for (var i in that.moduleList) {
							for (var j in moduleArray) {
								if (that.moduleList[i].APPFunID == moduleArray[j]) {
									usedList.push(that.moduleList[i])
								}
							}
						}
						that.usedList = usedList;

						that.getUndealNum();

					})
				},
				getUndealNum() {
					var that = this;
					FLD.ajax('APP_WCLJLTSN', {}, function (res) {
						for (var i in that.usedList) {
							var x = 0;
							for (var j in res.ds) {
								if (that.usedList[i].APPFunID == res.ds[j].APPFunID) {
									x = 1;
									that.$set(that.usedList[i], 'unDealNum', res.ds[j].JCNT);
								}
							}
							if (x == 0) {
								that.$set(that.usedList[i], 'unDealNum', 0);
							}

						}
					});
				},
				setDataRefresh() {
					var that = this;
					that.isRotate = true;
					FLD.ajax('APP_SYSXAN', { S_BranchID: userInfo.S_BranchID }, function (res) {
						that.getUserfulData(1);
					}, 'toast');
				},
				getUserfulData(type) {
					var that = this;
					if (type == 1) {
						that.isRotate = true;
					}

					FLD.ajax('AP_SYSJTJ', { S_BranchID: userInfo.S_BranchID }, function (res) {
						setTimeout(function () {
							that.isRotate = false;
							that.statistics = res.ds[0];
						}, 1000)
					}, 'toast')
				},
				searchInventory() {
					var that = this;
					api.openWin({
						name: 'inventory',
						url: 'inventory.html',
						reload: true,
						slidBackEnabled: false,
						allowEdit: false,
						pageParam: {
							searchKey: that.indexSearchKey
						}
					})
				},
				openScan() {
					var that = this;
					FNScanner.open({
						autorotation: true
					}, function (ret, err) {
						if (ret) {
							if (ret.eventType == 'success') {
								var obj = {
									S_Type: 60,
									S_Cont: '',
									S_BranchID: userInfo.S_BranchID,
									S_SXZ: '',
									S_StockID: userInfo.S_StockID,
									S_CargoID: userInfo.S_CargoID,
									S_BarCode: ret.content,
									S_PriceN: 0,
									S_ProductID: 0
								}
								FLD.ajax('AP_BasList', obj, function (res) {
									if (res.ds.length == 0) {
										layer.open({
											content: '当前二维码未查询到商品!',
											skin: 'msg',
											time: 2
										});
										return false;
									}
									var row = res.ds[0];
									api.openWin({
										name: 'inventory',
										url: 'inventory.html',
										reload: true,
										slidBackEnabled: false,
										allowEdit: false,
										pageParam: {
											searchKey: row.name
										}
									})

								})
							}
						} else {
							layer.open({
								content: '未查询到对应产品!',
								skin: 'msg',
								time: 2
							});
						}
					});
				},
				openPage(row) {
					var pageParam = {}
					if (row.Para) {
						var paraArray = row.Para.split(';');
						for (var i in paraArray) {
							var paraRowArray = paraArray[i].split('=');
							pageParam[paraRowArray[0]] = paraRowArray[1]
						}
					}
					pageParam.titleName = row.APFunName;
					if (row.FunType == '自定义') {
						if (row.AP_Link == 'trip/branchList') {
							var obj = {
								S_Type: 666,
								S_Cont: '',
								S_BranchID: userInfo.S_BranchID,
								S_SXZ: '',
								S_StockID: userInfo.S_StockID,
								S_CargoID: userInfo.S_CargoID,
								S_BarCode: '',
								S_PriceN: 0,
								S_ProductID: 0
							}
							FLD.ajax('AP_BasList', obj, function (res) {
								var filterResult = res.ds;
								if (filterResult.length == 1) {
									api.openWin({
										name: 'tripList',
										url: 'trip/tripList.html',
										reload: true,
										slidBackEnabled: false,
										allowEdit: false,
										pageParam: {
											branchData: filterResult[0]
										}
									})
								} else {
									api.openWin({
										name: row.AP_Link,
										url: row.AP_Link + '.html',
										reload: true,
										slidBackEnabled: false,
										allowEdit: row.AP_Link == 'vin' ? true : false,
										pageParam: pageParam
									})
								}
							})
						} else {
							api.openWin({
								name: row.AP_Link,
								url: row.AP_Link + '.html',
								reload: true,
								slidBackEnabled: false,
								allowEdit: row.AP_Link == 'vin' ? true : false,
								pageParam: pageParam
							})
						}

					} else if (row.FunType == '配置表单') {

						api.openWin({
							name: 'formConfig',
							url: 'common/formConfig.html',
							reload: true,
							slidBackEnabled: false,
							pageParam: pageParam
						})
					} else if (row.FunType == '配置列表') {
						api.openWin({
							name: 'formHistoricalDocuments',
							url: 'common/formHistoricalDocuments.html',
							reload: true,
							slidBackEnabled: false,
							pageParam: pageParam
						})
					} else if (row.FunType == '配置图表') {
						api.openWin({
							name: 'formConfigChart',
							url: 'common/formConfigChart.html',
							reload: true,
							slidBackEnabled: false,
							pageParam: pageParam
						})
					} else if (row.FunType == '配置报表') {
						api.openWin({
							name: pageParam.objName + '_0',
							url: 'common/formConfigReport.html',
							reload: true,
							slidBackEnabled: false,
							pageParam: pageParam
						})
					}

				},
				// getNoticeList() {
				// 	var that = this;
				// 	FLD.ajax('AP_XLCCZTN', { S_BranchID: userInfo.S_BranchID }, function (res) {
				// 		for (var i in res.ds) {
				// 			if (res.ds[i].FZS < 60) {
				// 				res.ds[i].FZSVal = res.ds[i].FZS + '分钟前'
				// 			} else {
				// 				res.ds[i].FZSVal = parseInt(res.ds[i].FZS / 60) + '小时前'
				// 			}
				// 		}
				// 		that.noticeList = res.ds;
				// 	}, 'toast')
				// },
				openWinPage(url) {
					var that = this;
					if (url == 'dataAggregation') {
						api.openWin({
							name: url,
							url: 'new_' + url + '.html',
							reload: true,
							slidBackEnabled: false,
							pageParam: {
								PID: that.statistics.PID,
								PName: that.statistics.PName
							}
						})
					} else {
						api.openWin({
							name: url,
							url: url + '.html',
							reload: true,
							slidBackEnabled: (url == 'pscan' ? true : false)
						})
					}

				},
				openWinHPage(type, tabActive) {
					api.openWin({
						name: 'historicalDocuments',
						url: 'common/historicalDocuments.html',
						reload: true,
						slidBackEnabled: false,
						pageParam: {
							type: type,
							tabActive: tabActive
						}
					})
				}
			}
		})
	};
</script>

</html>